#!/usr/bin/python

###############################
## A base function for plots ##
###############################

#######################################################      
## Set PyRoot Environment and PlotConfig Path first ###
#######################################################
import sys
ROOTSYS = '/afs/atlas.umich.edu/opt/root/lib'
sys.path.append(ROOTSYS)
PlotConfig='../'
PlotConfig2='.'
sys.path.append(PlotConfig)
sys.path.append(PlotConfig2)

#####################
## Import Module  ###
#####################
import array
import os
import glob
from math import sqrt,fabs,sin
from ROOT import TFile,TTree,TChain,TBranch,TH1,TH1F,TList
from ROOT import TLorentzVector
from ROOT import THStack,TCanvas,TLegend,TColor,TPaveText
from ROOT import gStyle,gDirectory

####################
## Import Template #
####################
from plot_template_label import plot_template
from plot_template_4lep import plot_template_combined

############################
## Load Atlas Plot Style ###            
############################

from plot_style import atlas_style
atlas_style()

###############
## Plotting ###
###############
RatioSize=0.2
RatioErr=-1
RatioMin,RatioMax=0,3
RatioAdj=0

ShowMCErr=-1
MCErree=0.03157
MCErrmm=0.01276
MCErrll=0.01584

plot_config='plot_configure'


#ATLAS='ATLAS For Approval'
ATLAS='ALTAS Preliminary'
figFormat='all'
ch_xleg=0.57

xlabel=['crack e', 'loose++ e', 'medium++ e', 'tight++ e', 'loose #mu', 'combined #mu']

####### SF, ele eta/phi
histoDir='NOM'
##### lepton Eta
Mmin, Mmax=0, 6
yscale=2.5
Rebin=1
binSize=Rebin*0.02
Events=str('Events')
Mmin, Mmax=0, 4
hname=histoDir+'_eeee_SF_LepType'
hxt='Lepton type'
plot_template(histodir=histoDir,hname=hname,hxt=hxt,hyt=Events,xlabel=xlabel,hrebin=Rebin,xmin=Mmin,xmax=Mmax,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,showATLAS=ATLAS,figformat=figFormat,ch_xleg=ch_xleg)
Mmin, Mmax=0, 6
Events=str('Events')
hname=histoDir+'_eemm_SF_LepType'
hxt='Lepton type'
plot_template(histodir=histoDir,hname=hname,hxt=hxt,hyt=Events,xlabel=xlabel,hrebin=Rebin,xmin=Mmin,xmax=Mmax,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,showATLAS=ATLAS,figformat=figFormat,ch_xleg=ch_xleg)
Events=str('Events')
hname=histoDir+'_eemm_SF_LepType'
hxt='Lepton type'
plot_template(histodir=histoDir,hname=hname,hxt=hxt,hyt=Events,xlabel=xlabel,hrebin=Rebin,xmin=Mmin,xmax=Mmax,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,showATLAS=ATLAS,figformat=figFormat,ch_xleg=ch_xleg)
Mmin, Mmax=4, 6
Events=str('Events')
hname=histoDir+'_mmmm_SF_LepType'
hxt='Lepton type'
plot_template(histodir=histoDir,hname=hname,hxt=hxt,hyt=Events,xlabel=xlabel,hrebin=Rebin,xmin=Mmin,xmax=Mmax,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,showATLAS=ATLAS,figformat=figFormat,ch_xleg=ch_xleg)
Mmin, Mmax=0, 6
hname=histoDir+'_incl_SF_LepType'
hxt='Lepton type'
plot_template(histodir=histoDir,hname=hname,hxt=hxt,hyt=Events,xlabel=xlabel,hrebin=Rebin,xmin=Mmin,xmax=Mmax,ratio=RatioSize,ratio_min=RatioMin,ratio_max=RatioMax,ratio_adj=RatioAdj,ratio_err=RatioErr,showATLAS=ATLAS,figformat=figFormat,ch_xleg=ch_xleg)
